﻿using FluentNHibernate.Mapping;

namespace ZQNB.Entity.Users
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table("SgLib_Users_User");
            Id(x => x.Id).GeneratedBy.GuidComb();

            Map(x => x.LoginName).Unique();
            Map(x => x.Name);
            Map(x => x.Nick);

        }
    }

    public class TeacherMap : SubclassMap<Teacher>
    {
        public TeacherMap()
        {
            Table("SgLib_Users_Teacher");
            KeyColumn("Id");

            HasMany(x => x.TeacherSubjects)
              .Inverse()
              .KeyColumn("TeacherId")
              .ForeignKeyConstraintName("FK_SgLib_TeacherSubject_Teacher")
              .Cascade.AllDeleteOrphan();
        }
    }
    public class TeacherSubjectMap : ClassMap<TeacherSubject>
    {
        public TeacherSubjectMap()
        {
            Table("SgLib_Users_TeacherSubject");
            Id(x => x.Id).GeneratedBy.GuidComb();

            Map(x => x.GradeCode);
            References(x => x.Teacher).Column("TeacherId").ForeignKey("FK_SgLib_TeacherSubject_Teacher");
        }
    }
}
